<?php

/**
 * @author Tuan anh
 * @copyright 2012
 */

class Time{
	public function getTimeForNow($id)
	{
		$sql ="SELECT timeend, timestampdiff(minute,now(),timeend) as minute,
		timestampdiff(hour,now(),timeend) as hour,
		timestampdiff(day,now(),timeend) as day FROM tbl_job WHERE id =$id";

		$data = Yii::app()->db->createCommand($sql)->queryRow();
		if ( $data["day"] == 0 && $data["hour"] == 0 ){
			return $data["minute"].' m';
		}elseif ($data["day"] == 0) {
			$min = $data["minute"] - $data["hour"]*60;
			return $data["hour"]."h $min m";
		}else{
			$h = $data["hour"] - $data["day"] * 24;
			return $data["day"]."d $h".'h';
		}
	}
}


?>